-- Use the Stargate addon to add LS, RD and Wire support to this entity
StarGate.LifeSupportAndWire(ENT)

include("autorun/shared/StargateExtras.lua")

ENT.Type             = "anim"
ENT.Base             = "base_gmodentity"

ENT.PrintName        = "Gate Overloader"
ENT.WireDebugName    = "Gate Overloader"
ENT.Author           = "PyroSpirit"
ENT.Contact		      = "forums.facepunchstudios.com"

ENT.Spawnable        = false
ENT.AdminSpawnable   = false

ENT.AutomaticFrameAdvance = true

ENT.energyPerSecond       = 2500
ENT.energyPerCycle        = 500
ENT.coolingPerCycle       = 300

ENT.coherentBeamColour = "255 50 50"
ENT.incoherentBeamColour = "200 200 255"

-- Get the position of the beam emitter on the overloader
function ENT:GetEmitterPos()
   local model = self.Entity:GetModel()

   if(model == "models/portal/turret.mdl") then
      return self.Entity:GetPos() + (self.Entity:GetAngles():Forward() * 11)
   elseif(model == "models/pyro_overloader/overloader.mdl") then
      return StargateExtras:GetEntityCentre(self.Entity) + 
             (self.Entity:GetAngles():Up() * 30) + 
             (self.Entity:GetAngles():Forward() * 70)
   else
      return StargateExtras:GetEntityCentre(self.Entity) + 
             (self.Entity:GetForward() * self.Entity:BoundingRadius())
   end
end

function ENT:IsActive()
   return self.Entity:GetNetworkedBool("isActive", self.isActive == true)
end

function ENT:IsFiring()
   return self.Entity:GetNetworkedBool("isFiring", self.isFiring == true)
end

function ENT:IsBeamCoherent()
   return self.Entity:GetNetworkedBool("isBeamCoherent", self.isBeamCoherent == true)
end

function ENT:GetBeamColour()
   if(self:IsBeamCoherent()) then
      return self.coherentBeamColour
   else
      return self.incoherentBeamColour
   end
end

function ENT:GetLocalGate()
   return self.Entity:GetNetworkedEntity("localGate", nil)
end

function ENT:GetRemoteGate()
   return self.Entity:GetNetworkedEntity("remoteGate", nil)
end

function ENT:GetOutboundBeam()
   if(self:IsBeamCoherent()) then
      return self.Entity:GetNetworkedEntity("outBeam", nil)
   else
      return nil
   end
end
